#!/bin/bash

# 设置Jenkins端口
JENKINS_PORT="8080"

# 安装Jenkins
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install -y jenkins

# 修改Jenkins默认端口
sudo sed -i "s/HTTP_PORT=8080/HTTP_PORT=${JENKINS_PORT}/" /etc/default/jenkins

# 注册为服务并设置开机自启
sudo systemctl enable jenkins
sudo systemctl restart jenkins

echo "Jenkins安装完成并已设置为开机自启，端口为${JENKINS_PORT}"